package vn.pdg.zoombie.ui.adapter;

import java.util.ArrayList;

import vn.pdg.zoombie.bean.Image;
import vn.pdg.zoombie.bussiness.ImageLoader;
import vn.pdg.zoombie.common.LogDebug;
import vn.pdg.zoombie.ui.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

public class AdapterImagePicker extends BaseAdapter {
	
	private ArrayList<Image> listImages;
	private int totalImages;
	private LayoutInflater inflater;
	private final String TAG = "AdapterImagePicker";
	private ImageLoader imageLoader;
	public AdapterImagePicker(Context context,	ArrayList<Image> listImages,int typeLoader) {
		// TODO Auto-generated constructor stub
		this.listImages 	= listImages;
		this.totalImages 	= listImages.size();
		inflater 			= LayoutInflater.from(context);
		imageLoader 		= new ImageLoader(context, typeLoader);
		
	}

	public int getCount() {
		return totalImages;
	}

	public Object getItem(int position) {
		// return photos.get(position);
		return null;
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(final int position, View convertView,
			ViewGroup parent) {

		LogDebug.i(TAG, position + " ");
		ViewHolder mViewHolder;
		if (convertView == null) {

			convertView = inflater
					.inflate(R.layout.item_image_picker, null);

			mViewHolder = new ViewHolder();

			mViewHolder.imagePicker = (ImageView) convertView
					.findViewById(R.id.image_picker);

			convertView.setTag(mViewHolder);

		} else {
			mViewHolder = (ViewHolder) convertView.getTag();

		}
		
		Image image = listImages.get(position);
		String url = image.getUrl();
		String orientation = null;
		int degree = 0;
		orientation = image.getOrientation();
		
		if(orientation!=null)
			degree = Integer.parseInt(orientation);

		
		imageLoader.DisplayImage(url,mViewHolder.imagePicker, degree);
		


		return convertView;
	}

	private class ViewHolder{
		private ImageView imagePicker;
	}
	
	public ImageLoader getImageLoader(){
		return imageLoader;
	}
}
